package ar.edu.unq.tpi.labso.rochi.agendaRochi.Wicket.contacto;

import model.Aplicacion.Agenda;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

import simulaPersistencia.CiudadHome;
import ar.edu.unq.tpi.labso.rochi.agendaRochi.Wicket.HomePage;
import ar.edu.unq.tpi.labso.rochi.agendaRochi.Wicket.apliccion.ContactoDatProvider;
import clasesPrincipales.Ciudad;
import clasesPrincipales.Contacto;

public class AgregarContactoPage extends WebPage{
	
	private static final long serialVersionUID = 1L;

	
	public AgregarContactoPage() {
		
		super(new CompoundPropertyModel<Contacto>(
				Agenda.getHome(Contacto.class).createExample()));
		Form<Contacto> form = new Form<Contacto>("contactoAgregarForm");		
		this.add(form);

		form.add(new Label("lbl_nombre","Nombre"));
		form.add(new TextField<String>("nombre"));
		form.add(new Label("lbl_telefono","Telefono"));
		form.add(new TextField<String>("telefono"));//textBox
		form.add(new Label("lbl_mail","Mail"));
		form.add(new TextField<String>("mail"));
		form.add(new Label("lbl_ciudad","Ciudad"));
		form.add(new DropDownChoice("ciudad", ((CiudadHome) Agenda.getHome(Ciudad.class)).buscarTodos()));//combo
	
	
        final ContactoDatProvider provider =new ContactoDatProvider();

		form.add(new SubmitLink("botonAgregarContacto"){
		private static final long serialVersionUID = 1L;
		public void onSubmit()  {
			provider.agregar((Contacto)AgregarContactoPage.this.getDefaultModelObject());
			this.setResponsePage(new HomePage());
		}});
		
		form.add(new Link("botonVolverHome"){
			private static final long serialVersionUID = 1L;
			public void onClick() {
				AgregarContactoPage.this.setResponsePage(new HomePage());
			}});
			
			};
}

